//测试最小链表
//Compile: gcc min_list_test.c min_list.c -o min_list_test
//Run: ./min_list_test

#include "min_list.h"
#include "time_printer.h"
#include "stdio.h"
#include "string.h"
#include <time.h>

int main(){
    int length = 10;

    //初始化测试
    struct minlist* minlist = create_minlist(length);
    // minlist->count = length;
    print_minlist(minlist);
    // printf("address of minlist:%lu, entries:%lu\n",(unsigned long)minlist,(unsigned long)(minlist->entries));

    //插入测试
    srand((unsigned)time(0));
    struct minlist_entry tmp_entry;

    void* timer = init_record_time_printer("vector computer");
    for(int i=1;i<=50;i++){
        tmp_entry.id = i;
        float randnum = 3.123+rand()%100;
        tmp_entry.distance = (1+randnum*randnum);//((randnum*randnum)%1000)/1000.0;
        int index = insert_minlist(minlist, &tmp_entry);
        printf("insert into %d\n",index);
    }   
    record_last_time(timer);

    //打印测试
    print_minlist(minlist);

    //取值测试
    struct minlist_entry* ret;
    ret = get_mins(minlist);
    printf("has %d data\n",minlist->count);
    for(int i=0;i<minlist->count;i++){
        printf("id:%d distance:%f\n",ret[i].id,ret[i].distance);
    }

    destory_minlist(minlist);

    return 0;
}